<?php
/**
 * Created by PhpStorm.
 * User: lhl
 * Date: 2019/9/4
 * Time: 21:50
 * Features: 跨域/响应options请求
 */

namespace app\adminapiv3\middleware;

use think\Request;

header("Access-Control-Allow-Origin: *" );
header("Access-Control-Allow-Methods:GET,POST,OPTIONS,PATCH,PUT,DELETE");
header('Access-Control-Allow-Headers:accesstoken, permissiontoken, Origin, X-Requested-With, Content-Type, Content-Length, Accept, Accept-Encoding');
header('Access-Control-Max-Age: 3600000');

class CrossDomain
{
    /**
     * 前置中间件: 跨域/响应options请求
     */
    public function handle(Request $request,\Closure $next){
        if($request->isOptions()){
            returnErrJson(200, 'Options请求');
        }
        return $next($request);
    }

}